#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<vector<int>> ret;
    void subCombinationSum(vector<int>& candidates, int& target, int preIndex, vector<int>& v, int& sum)
    {
        for (int i = preIndex;i < candidates.size();++i)
        {
            v.push_back(candidates[i]);
            sum += candidates[i];
            if (sum >= target)
            {
                if (sum == target) ret.push_back(v);
                v.pop_back();
                sum -= candidates[i];
                return;
            }
            subCombinationSum(candidates, target, i, v, sum);
            v.pop_back();
            sum -= candidates[i];
        }
    }
    vector<vector<int>> combinationSum(vector<int>& candidates, int target)
    {
        sort(candidates.begin(), candidates.end());
        vector<int> v;
        int sum = 0;
        subCombinationSum(candidates, target, 0, v, sum);
        return ret;
    }
};